package com.jiangnan.warehouse_management.controller;

import com.jiangnan.warehouse_management.common.Result;
import com.jiangnan.warehouse_management.dto.request.InboundRecordRequest;
import com.jiangnan.warehouse_management.dto.response.InboundRecordQueryResponse;
import com.jiangnan.warehouse_management.dto.response.InboundRecordResponse;
import com.jiangnan.warehouse_management.pojo.InboundRecord;
import com.jiangnan.warehouse_management.service.InboundRecordService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class InboundRecordController {

    private final InboundRecordService inboundRecordService;

    @GetMapping("/getInboundRecords")
    public Result<InboundRecordQueryResponse> getInboundRecords(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "itemId", required = false) Integer itemId,
            @RequestParam(value = "warehouseId", required = false) Integer warehouseId,
            @RequestParam(value = "startTime", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Timestamp startTime,
            @RequestParam(value = "endTime", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Timestamp endTime) {
        
        InboundRecordQueryResponse data = inboundRecordService.getInboundRecords(
            page, pageSize, itemId, warehouseId, startTime, endTime);
        return Result.success(data);
    }

    @PostMapping("/createInboundRecord")
    public Result<InboundRecord> createInboundRecord(@Valid @RequestBody InboundRecordRequest request) {
        InboundRecord data = inboundRecordService.createInboundRecord(request);
        return Result.success(data);
    }

    @GetMapping("/InboundRecordsById/{id}")
    public Result<InboundRecordResponse> getInboundRecordById(@PathVariable Integer id) {
        InboundRecordResponse data = inboundRecordService.getInboundRecordById(id);
        return Result.success(data);
    }
} 